<template>
    <IModal v-model="defaultValue" :loading="loading" :width="500" title="添加理货明细">
        <Form :model="data" :label-width="100" :rules="ruleValidate" ref="formCreate">
            <FormItem label="来货条码" prop="barcode">
                <Input v-model="data.barcode"></Input>
            </FormItem>
            <FormItem label="产品数量" prop="quantity">
                <Input v-model="data.quantity" number></Input>
            </FormItem>
            <FormItem label="产品批次号" prop="batch">
                <Input v-model="data.batch"></Input>
            </FormItem>
            <FormItem label="产品属性" prop="attribute">
                <RadioGroup v-model="data.attribute">
                    <Radio :label="0">良品</Radio>
                    <Radio :label="1">不良品</Radio>
                </RadioGroup>
            </FormItem>
            <alert banner type="warning" style="margin-bottom: 0;">
                如果没有批次号请用
                <Tag>-</Tag>
                代替
            </alert>
        </Form>
        <div slot="footer">
            <Button type="primary" icon="ios-add" @click="submit('formCreate')">确认</Button>
            <Button type="warning" icon="md-log-out" @click="defaultValue = false">返回</Button>
        </div>
    </IModal>
</template>

<script>
    import contentDrawer from "../../../mixins/contentDrawer";
    import IModal from "../../../components/content/modal";

    export default {
        name: "detail",
        components: {IModal},
        mixins: [contentDrawer],
        data() {
            return {
                data: {
                    barcode: this.props.barcode,
                    attribute: 0
                },
                ruleValidate: {
                    barcode: [{required: true, message: "来货条码"}],
                    quantity: [{required: true, message: "产品数量", type: 'number'}],
                    batch: [{required: true, message: "产品批次号"}],
                    attribute: [{required: true, message: "产品属性"}],
                }
            }
        },
        methods: {
            submit(name) {
                this.validate(name).then(() => {
                    this.$http.post(`warehousing/tally/${this.props.id}/detail`, this.data).then(() => {
                        this.defaultValue = false;
                    }).finally(() => {
                        this.loading = false;
                    });
                });
            }
        }
    }
</script>

<style scoped>

</style>